package com.workcell.workdata.xthings.kafka.listener;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.springframework.kafka.listener.KafkaListenerErrorHandler;
import org.springframework.kafka.listener.ListenerExecutionFailedException;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

/**
 * @Author 廖博文
 * @Date 2023/5/25 13:45
 * @Description 异常处理
 */
@Slf4j
@Component
public class KafkaListenerResultHandler implements KafkaListenerErrorHandler {

	@Override
	public Object handleError(Message<?> message, ListenerExecutionFailedException e) {
		return new Object();
	}

	@Override
	public Object handleError(Message<?> message, ListenerExecutionFailedException exception, Consumer<?, ?> consumer) {
		log.error("Kafka消息队列消费日志，消费时异常：消息详情[{}]，topic[{}]，消费者详情[{}]，异常[{}]", message, consumer.listTopics(), consumer.groupMetadata(),exception);
		return KafkaListenerErrorHandler.super.handleError(message, exception, consumer);
	}
}
